﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portfolio.Presenters.Interfaces;
using Portfolio.IViews;
using Portfolio.BL.Menu;
using Portfolio.BL.Interfaces;
using Portfolio.Entities;

namespace Portfolio.Presenters
{
    public class DefaultPresenter : IDefaultPresenter
    {
        private IDefaultView _view;
        private IMenuTopBL _menuTopBL;
        

        public DefaultPresenter(IDefaultView view)
        {
            _view = view;
            _menuTopBL = new MenuTopBL();
            this.Initialize();
        }

        public void Initialize()
        {            
            this._view.LoadMenuTop += new EventHandler<EventArgs>(_viewLoadMenuTop);
            this._view.ClickItemMenuTop += new EventHandler<EventArgs>(_viewClickMenuTop);
        }

        private void _viewClickMenuTop(object sender, EventArgs e)
        {
            try
            {
                MenuTopArticleV _menuTopArticleV = new MenuTopArticleV();
                _menuTopArticleV = _menuTopBL.ReturnArticleByMenuItem(_view.IdItemMenu);
                _view.TitleArticle = _menuTopArticleV.Title;
                _view.TextArticle = _menuTopArticleV.Text;
                _view.SubTitleArticle = _menuTopArticleV.SubTitle;
                _view.SubTextArticle = _menuTopArticleV.SubText;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }

        private void _viewLoadMenuTop(object sender, EventArgs e)
        {            
            try
            {                
                _view.MenuTopList = _menuTopBL.ReturnMenuTop();               
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }        
    }
}
